package com.company.exp2.util;

import java.util.Random;

/**
 * @author dyy
 *
 * 请不要修改内部细节
 */
public final class DistributionGenerator {

    private final int n;
    private final int lambda;
    Random random;

    {
        random = new Random();
    }

    public DistributionGenerator(int poissonExpected, int ExpExpected) {
        n = poissonExpected * 5;
        lambda = ExpExpected;
    }

    public int getPoisson() {
        int result = 0;
        for(int i = 0 ; i < n ; i ++) {
            int p = 5;
            if (random.nextInt(p) == 0) {
                result ++;
            }
        }
        return result;
    }

    public int getExp(){
        int count = 0;
        double u = random.nextDouble();
        double f = 0.0;
        while(u >= f) {
            count++;
            f = 1 - Math.exp(-1.0 * (1.0 / lambda) * count);
        }
        return count;
    }

}
